home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
cppmatrx.zip
/
MATPARSE.C
< prev
next >
Wrap
Text File
|
1991-02-02
|
1KB
|
77 lines
#include <math.h>
#include <iostream.h>
#include "matrix.h"
#include "matparse.h"
static char current_token;
matrix expression (void)
{
matrix left = term ();
matrix right ("*",2);
matrix temp ("*",2);
while (1) {
switch (current_token) {
case '+':
right = term ();
temp = left+right;
left = temp;
break;
case '-':
right = term ();
temp = left-right;
left = temp;
break;
case '!':
return left;
default:
matrix_error ("Invalid character in expression.");
}
}
}
matrix term (void)
{
matrix left = primary ();
matrix right ("*",2);
matrix temp ("*",2);
while (1) {
switch (get_token ()) {
case '*':
right = primary ();
temp = left*right;
left = temp;
break;
default:
return left;
}
}
}
matrix primary (void)
{
char ch;
matrix temp ("*",2);
cin >> ch;
cin >> temp;
cin >> ch;
return temp;
}
char get_token (void)
{
cin >> current_token;
return current_token;
}